<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
<body>
<style>
#dataTable tr th{
  background: #FAFAFA;
  text-align: center;
}
#dataTable td{
	word-break:break-all;
	height: 30px;
	padding: 0px;
	background: #FFF;
}
#dataTable .layui-input:focus,#dataTable select:focus{
  border-bottom: solid 2px #5DC5B8;
  background: #E3F7F7;
}
#dataTable .layui-input{
	padding-left:12px;
	padding-right:12px;
	border-radius: 0px;
	border: none;
	text-align: center;
	border-bottom:solid 2px #FFFFFF; ;
}
.price-input{
	text-align: center;
}


.moblie-box .top-box{
    margin-bottom: 20px;
}
.moblie-box .li{
	margin: 0px;
	float: left;
	border: 1px solid #CCCCCC;
	border-right: none;
	border-bottom: none;
	margin-bottom: 20px;
}
.moblie-box .li .layui-row{
	padding: 0px;
	margin: 0px;
}
.moblie-box .li input[type=text],.moblie-box .li select{
	text-align: center;
	border-radius: 0px;
	border: none;
}
.moblie-box .li div[class^="layui-col-xs"]{
	border: 1px solid #CCCCCC;
	border-left: none;
	border-top: none;
}
.moblie-box .li .subtitle{
	background-color: #EEEEEE;
	text-align: center;
	height: 39px;
	line-height: 39px;
}
.moblie-box .li .unit{
	border: none;
}
.moblie-box .extend .layui-row{
	margin: 5px;
	margin-bottom: 15px;
}
.moblie-box .invoice-btn{
	border-top: 1px solid #CCC;
	background-color: #FFFFFF;
	height: 60px;
	width: 100%;
	text-align: center;
	position: fixed;
	bottom: 0px;
	left: 0px;
	padding-top: 8px;
	z-index: 20;
}
.xd-staff{
    padding-left: 30px;
}
.head-box{
    display: flex;
    justify-content: space-between;
    content: none !important;
}
</style>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
        
            {if isMobile()}
            <!--移动端-->
            <div class="moblie-box">
                <div class="layui-col-xs12 top-box">
                    <textarea id="aitext" placeholder="请输入要AI识别的采购信息" class="layui-textarea"></textarea>
                </div>
                <div class="layui-col-xs8 top-box">
                    <div class="layui-input-inline2 input-group">
                        <span class="input-group-addon">下单时间</span>
                        <input type="text" id="create_time" name="create_time" value="{$model.create_time??date('Y-m-d H:i:s')}" placeholder="请输入添加时间" class="layui-input"  verify="must">
                    </div>
                </div>
                <div class="layui-col-xs4 top-box" style="padding-left: 10px;">
                    <button type="button" class="pear-btn pear-btn-primary ai-read-but">
                        <i class="layui-icon layui-icon-dialogue"></i>
                        确定识别
                    </button>
                </div>
                
                {if !$action_up}
                <div class="layui-col-xs12 top-box">
                    <div class="layui-form-item">
                        <div class="layui-col-md12 xd-staff">
                            {php}if(!$action_up) $model["staff_id"]=0;{/php}
                            {volist name="staff_list" id="v"}
                            {if $v.id == $model.staff_id}
                            <input type="radio" name="staff_id" title="{$v.name}" value="{$v.id}" checked lay-filter="staff_id">
                            {else/}
                            <input type="radio" name="staff_id" title="{$v.name}" value="{$v.id}" lay-filter="staff_id">
                            {/if}
                            {/volist}
                        </div>  
                    </div>        
                </div>
                {else}
                <div class="layui-col-xs12 top-box">
                   <div class="layui-input-inline input-group">
                       <span class="input-group-addon">业务员</span>
                        <input type="text" name="sup_code" value="{$staff_name}" disabled placeholder="" class="layui-input">
                    </div>
                </div>
                {/if}
                
                {for start="0" end="$maxlist" name="i"}
                <div class="li list-table-row" data-id="{$i}">
                	<div class="layui-row">
                		<div class="layui-col-xs1 subtitle">{$i+1}</div>
                		<div class="layui-col-xs6">
                			<input class="layui-input" type="text" data-id="{$i}" name="info[fabric_code][]" value="{$Tinfo[$i]['fabric_code']??''}" placeholder="编号">
                			<input class="layui-input" type="hidden" data-id="fabric_id{$i}" name="info[fabric_id][]" value="{$Tinfo[$i]['fabric_id']??0}">
                			<input class="layui-input" type="hidden" data-id="infoid{$i}" name="info[infoid][]" value="{$Tinfo[$i]['id']??''}">
                		</div>
                		<div class="layui-col-xs2 subtitle">色号</div>
                		<div class="layui-col-xs3"><input class="layui-input popovers" type="text" name="info[color_code][]" value="{$Tinfo[$i]['color_code']??''}" placeholder="色号" data-original-title="" data-content="" data-placement="top" data-trigger="hover">
                        <input type="hidden" data-id="is_change{$i}" value="0">
                		<input type="hidden" name="info[colorname][]" value="{$Tinfo[$i]['colorname']??''}">
                		<input type="hidden" name="info[colorval][]" value="{$Tinfo[$i]['colorval']??''}">
                		<input type="hidden" name="info[gray][]" value="{$Tinfo[$i]['gray']??''}">
                		<input type="hidden" name="info[onumber][]" value="{$Tinfo[$i]['onumber']??''}">
                		<input type="hidden" name="info[ocolorid][]" value="{$Tinfo[$i]['ocolorid']??''}">
                	</div>
                	{php}
                	  if(!isset($Tinfo[$i]['unit'])){
                	      $Tinfo[$i]['unit']='';
                	  }
                	  if(!isset($Tinfo[$i]['exp_method'])){
                	      $Tinfo[$i]['exp_method']='';
                	  }
                	  if(!isset($Tinfo[$i]['exp_name'])){
                	      $Tinfo[$i]['exp_name']='';
                	  }
                	{/php}
                	</div>
                	<div class="layui-row">
                		<div class="layui-col-xs7"><input class="layui-input" type="text" data-id="fabric_name{$i}" name="info[fabric_name][]" value="{$Tinfo[$i]['fabric_name']??''}"  placeholder="品名"></div>
                		<div class="layui-col-xs2 subtitle">颜色名</div>
                		<div class="layui-col-xs3">
                			<input class="layui-input popovers" type="text" name="info[color_name][]" value="{$Tinfo[$i]['color_name']??''}">
                			<input type="hidden" name="info[color_hex][]" value="{$Tinfo[$i]['color_hex']??''}">
                			<input type="hidden" name="info[gray][]" value="{$Tinfo[$i]['gray']??''}">
                		</div>
                	</div>
                	<div class="layui-row">
                		<div class="layui-col-xs5">
                            <input class="layui-input" type="text" data-id="count{$i}" name="info[count][]" value="{$Tinfo[$i]['count']??''}" placeholder="数量">
                        </div>
                        <div class="layui-col-xs2">
                            <select class="layui-input" data-id="unit{$i}" name="info[unit][]" lay-ignore>
                              <option value="米" {eq name="Tinfo[$i]['unit']" value='米'}selected{/eq}>米</option>
                              <option value="条" {eq name="Tinfo[$i]['unit']" value='条'}selected{/eq}>条</option>
                              <option value="块" {eq name="Tinfo[$i]['unit']" value='块'}selected{/eq}>块</option>
                              <option value="样" {eq name="Tinfo[$i]['unit']" value='样'}selected{/eq}>样</option>
                              <option value="KG" {eq name="Tinfo[$i]['unit']" value='KG'}selected{/eq}>KG</option>
                            </select>
                        </div>
                		<div class="layui-col-xs2 subtitle">颜色</div>
                		<div class="layui-col-xs3" id="color{$i}" style="height: 39px;"></div>
                	</div>
                	<div class="layui-row">
                		<div class="layui-col-xs2 subtitle">供应号</div>
                		<div class="layui-col-xs4">
                            <input class="layui-input" type="text" data-id="sup_code{$i}" name="info[sup_code][]" value="{$Tinfo[$i]['sup_code']??''}">
                            <input class="layui-input" type="hidden" data-id="sup_id{$i}" name="info[sup_id][]" value="{$Tinfo[$i]['sup_id']??''}">
                            <input class="layui-input" type="hidden" data-id="cut_payment{$i}" name="info[cut_payment][]" value="{$Tinfo[$i]['cut_payment']??''}">
                        </div>
                		<div class="layui-col-xs2 subtitle">对应色</div>
                		<div class="layui-col-xs4">
                            <input class="layui-input" type="text" data-id="sup_color{$i}" name="info[sup_color][]" value="{$Tinfo[$i]['sup_color']??''}">
                        </div>
                	</div>
                    <div class="layui-row">
                    	<div class="layui-col-xs2 subtitle">商家</div>
                    	<div class="layui-col-xs4">
                            <input class="layui-input" type="text" data-id="sup_name{$i}" name="info[sup_name][]" value="{$Tinfo[$i]['sup_name']??''}">
                        </div>
                    	<div class="layui-col-xs2 subtitle">发货</div>
                    	<div class="layui-col-xs4">
                            <select class="layui-input" name="info[exp_method][]" data-id="exp_method{$i}" lay-ignore>
                              <option value=""></option>
                              {foreach name="options.exp_method" item="v"}
                                  {if !$action_up}
                                  <option value="{$v.name}">{$v.name}</option>
                                  {elseif $v.name == $Tinfo[$i]['exp_method']??''}
                                  <option value="{$v.name}" selected="selected">{$v.name}</option>
                                  {else/}
                                  <option value="{$v.name}">{$v.name}</option>
                                  {/if}
                              {/foreach}
                            </select>
                        </div>
                    </div>
                	<div class="layui-row">
                		<div class="layui-col-xs8 subtitle">
                			<input class="layui-input" type="text" data-id="remark{$i}" name="info[remark][]" value="{$Tinfo[$i]['remark']??''}" placeholder="备注">
                		</div>
                        <div class="layui-col-xs4">
                            <select class="layui-input" name="info[exp_name][]" data-id="exp_name{$i}" lay-ignore>
                              <option value=""></option>
                              {foreach name="options.exp_name" item="v"}
                                  {if !$action_up}
                                  <option value="{$v.name}">{$v.name}</option>
                                  {elseif $v.name == $Tinfo[$i]['exp_name']??''}
                                  <option value="{$v.name}" selected="selected">{$v.name}</option>
                                  {else/}
                                  <option value="{$v.name}">{$v.name}</option>
                                  {/if}
                              {/foreach}
                            </select>
                        </div>
                	</div>
                </div>
                {/for}
                
                <div class="layui-col-xs12 top-box">
                    {php}if(!$action_up) $model["status"]=1;{/php}
                    {volist name="options.pur_status" id="v"}
                    {if $v.level == $model.status}
                    <input type="radio" name="status" title="{$v.name}" value="{$v.level}" checked lay-filter="pur_type">
                    {else/}
                    <input type="radio" name="status" title="{$v.name}" value="{$v.level}" lay-filter="pur_type">
                    {/if}
                    {/volist}
                </div>
                <div class="layui-col-xs12 top-box">
                    {php}if(!$action_up) $model["pur_type"]=1;{/php}
                    {volist name="options.pur_type" id="v"}
                    {if $v.id == $model.pur_type}
                    <input type="radio" name="pur_type" title="{$v.val}" value="{$v.id}" checked lay-filter="pur_type">
                    {else/}
                    <input type="radio" name="pur_type" title="{$v.val}" value="{$v.id}" lay-filter="pur_type">
                    {/if}
                    {/volist}
                </div>
                <div class="layui-col-xs12">
                    <textarea id="remark" placeholder="请输入备注" class="layui-textarea">{$model.remark??''}</textarea>
                </div>
            </div>
			{else}
            
            <!--电脑端-->
            <div class="pc-box">
                {if !$action_up}
                <div class="layui-row">
                    <div class="layui-col-md12">
                        <textarea id="aitext" placeholder="请输入要AI识别的采购信息" class="layui-textarea"></textarea>
                    </div>
                </div>
                {/if}
                <div class="head-box">
                    {if !$action_up}
    <!-- 				<div class="layui-col-md6">
                        <div class="layui-form-item">
                            <div class="layui-col-md6">
                                <div class="layui-input-inline2 input-group" style="width: 100%;">
                                    <span class="input-group-addon">员工</span>
                                    {if $action_up}
                                    <input type="text" id="search_input" class="layui-input search-input" value="{$model.staff.name}" readonly="readonly"/>
                                    {else/}
                                    <input type="text" id="search_input" class="layui-input search-input" verify="must" verify_tips="hide" url="{:U('staff.main/findname')}"/>
                                    {/if}
                                    <input type="hidden" name="cusid" verify="must" verify_tips="hide" value="{$model.cusid??''}"/>
                                    <div class="search-list" id="staff">
                                        <dl></dl>
                                    </div>
                                </div>
                            </div>   
                            <div class="layui-col-md4">
                                <span>&nbsp;</span>
                                <button type="button" class="pear-btn pear-btn-primary" id="staff-btn">搜索</button>
                            </div>
                        </div>
                    </div> -->
                    <div class="layui-col-md6">
                        <div class="layui-form-item">
                            <div class="layui-col-md12 xd-staff">
                                {php}if(!$action_up) $model["staff_id"]=0;{/php}
                                {volist name="staff_list" id="v"}
                                {if $v.id == $model.staff_id}
                                <input type="radio" name="staff_id" title="{$v.name}" value="{$v.id}" checked lay-filter="staff_id">
                                {else/}
                                <input type="radio" name="staff_id" title="{$v.name}" value="{$v.id}" lay-filter="staff_id">
                                {/if}
                                {/volist}
                            </div>  
                        </div>        
                    </div>
                    {else/}
                    <div class="layui-col-md8">
                        <div class="layui-form-item layui-inline">
                           <div class="layui-input-inline2 input-group">
                               <span class="input-group-addon">业务员</span>
                                <input type="text" name="sup_code" value="{$staff_name}" disabled placeholder="" class="layui-input">
                            </div>
                        </div>
                    </div>
                    {/if}
                    <div class="layui-col-md4" style="text-align: right;">
                        <div class="layui-form-item layui-inline">
                           <div class="layui-input-inline2 input-group">
                               <span class="input-group-addon">下单时间</span>
                               <input type="text" id="create_time" name="create_time" value="{$model.create_time??date('Y-m-d H:i:s')}" placeholder="请输入添加时间" class="layui-input"  verify="must">
                           </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">	
                    <div class="layui-col-md12">
                        <table class="layui-table" id="dataTable">
                            <thead>
                            <!-- <tr>
                                <td colspan="15" style="background-color:#F8F8F8;">加价提醒：<span id="markup_txt" style="color:#C00;"></span></td>
                            </tr> -->
                            <tr>
                                <th width="1%">序</th>
                                <th width="8%">编号</th>
                                <th width="10%">品名</th>
                                <th width="5%">色号</th>
                                <th width="2%"></th>
                                <th width="8%">颜色</th>
                                <th width="5%">数量</th>
                                <th width="5%">单位</th>
                                <th width="8%">供应号</th>
                                <th width="8%">对应色</th>
                                <th width="8%">商家</th>
                                <th width="8%">提货方式</th>
                                <th width="5%">物流</th>
                                <th width="19%">备注</th>
                            </tr>
                            </thead>
                            <tbody>
                                {for start="0" end="$maxlist" name="i"}
                                <tr class="list-table-row tr-row" data-id="{$i}">
                                    <td style="text-align:center;line-height:34px;background:#FAFAFA;">{$i+1}</td>
                                    <td>
                                      <input class="layui-input" type="text" data-id="{$i}" name="info[fabric_code][]" value="{$Tinfo[$i]['fabric_code']??''}">
                                      <input class="layui-input" type="hidden" data-id="fabric_id{$i}" name="info[fabric_id][]" value="{$Tinfo[$i]['fabric_id']??0}">
                                      <input class="layui-input" type="hidden" data-id="infoid{$i}" name="info[infoid][]" value="{$Tinfo[$i]['id']??''}">
                                    </td>
                                    <td><input class="layui-input" type="text" data-id="fabric_name{$i}" name="info[fabric_name][]" value="{$Tinfo[$i]['fabric_name']??''}"></td>
                                    <td>
                                        <input class="layui-input popovers" type="text" name="info[color_code][]" value="{$Tinfo[$i]['color_code']??''}" data-original-title="" data-content="" data-placement="top" data-trigger="hover">
                                        <input type="hidden" data-id="is_change{$i}" value="0">
                                    </td>
                                    <td id="color{$i}"></td>
                                    <td><input class="layui-input popovers" type="text" name="info[color_name][]" value="{$Tinfo[$i]['color_name']??''}">
                                    <input type="hidden" name="info[color_hex][]" value="{$Tinfo[$i]['color_hex']??''}">
                                    <input type="hidden" name="info[gray][]" value="{$Tinfo[$i]['gray']??''}">
                                    </td>
                                    {php}
                                      if(!isset($Tinfo[$i]['unit'])){
                                          $Tinfo[$i]['unit']='';
                                      }
                                      if(!isset($Tinfo[$i]['exp_method'])){
                                          $Tinfo[$i]['exp_method']='';
                                      }
                                      if(!isset($Tinfo[$i]['exp_name'])){
                                          $Tinfo[$i]['exp_name']='';
                                      }
                                    {/php}
                                    <td><input class="layui-input" type="text" data-id="count{$i}" name="info[count][]" value="{$Tinfo[$i]['count']??''}"></td>
                                    <td>
                                    <select class="layui-input" data-id="unit{$i}" name="info[unit][]" lay-ignore>
                                      <option value="米" {eq name="Tinfo[$i]['unit']" value='米'}selected{/eq}>米</option>
                                      <option value="条" {eq name="Tinfo[$i]['unit']" value='条'}selected{/eq}>条</option>
                                      <option value="块" {eq name="Tinfo[$i]['unit']" value='块'}selected{/eq}>块</option>
                                      <option value="样" {eq name="Tinfo[$i]['unit']" value='样'}selected{/eq}>样</option>
                                      <option value="KG" {eq name="Tinfo[$i]['unit']" value='KG'}selected{/eq}>KG</option>
                                    </select>
                                    </td>
                                    <td>
                                        <input class="layui-input" type="text" data-id="sup_code{$i}" name="info[sup_code][]" value="{$Tinfo[$i]['sup_code']??''}">
                                        <input class="layui-input" type="hidden" data-id="sup_id{$i}" name="info[sup_id][]" value="{$Tinfo[$i]['sup_id']??''}">
                                        <input class="layui-input" type="hidden" data-id="cut_payment{$i}" name="info[cut_payment][]" value="{$Tinfo[$i]['cut_payment']??''}">
                                    </td>
                                    <td><input class="layui-input" type="text" data-id="sup_color{$i}" name="info[sup_color][]" value="{$Tinfo[$i]['sup_color']??''}"></td>
                                    <td><input class="layui-input" type="text" data-id="sup_name{$i}" name="info[sup_name][]" value="{$Tinfo[$i]['sup_name']??''}"></td>
                                    <td>                                    
                                        <select class="layui-input" name="info[exp_method][]" data-id="exp_method{$i}" lay-ignore>
                                          <option value=""></option>
                                          {foreach name="options.exp_method" item="v"}
                                              {if !$action_up}
                                              <option value="{$v.name}">{$v.name}</option>
                                              {elseif $v.name == $Tinfo[$i]['exp_method']??''}
                                              <option value="{$v.name}" selected="selected">{$v.name}</option>
                                              {else/}
                                              <option value="{$v.name}">{$v.name}</option>
                                              {/if}
                                          {/foreach}
                                        </select>
                                    </td>
                                    <td>
                                        <select class="layui-input" name="info[exp_name][]" data-id="exp_name{$i}" lay-ignore>
                                          <option value=""></option>
                                          {foreach name="options.exp_name" item="v"}
                                              {if !$action_up}
                                              <option value="{$v.name}">{$v.name}</option>
                                              {elseif $v.name == $Tinfo[$i]['exp_name']??''}
                                              <option value="{$v.name}" selected="selected">{$v.name}</option>
                                              {else/}
                                              <option value="{$v.name}">{$v.name}</option>
                                              {/if}
                                          {/foreach}
                                        </select>
                                    </td>
                                    <td><input class="layui-input" type="text" data-id="remark{$i}" name="info[remark][]" value="{$Tinfo[$i]['remark']??''}"></td>
                                </tr>
                                {/for}
                                <tr>
                                    <td colspan="6" style="text-align: center;">
                                        {php}if(!$action_up) $model["status"]=1;{/php}
                                        {volist name="options.pur_status" id="v"}
                                        {if $v.level == $model.status}
                                        <input type="radio" name="status" title="{$v.name}" value="{$v.level}" checked lay-filter="pur_type">
                                        {else/}
                                        <input type="radio" name="status" title="{$v.name}" value="{$v.level}" lay-filter="pur_type">
                                        {/if}
                                        {/volist}
                                    </td>
                                    <td colspan="4" style="text-align: center;">
                                        {php}if(!$action_up) $model["pur_type"]=1;{/php}
                                        {volist name="options.pur_type" id="v"}
                                        {if $v.id == $model.pur_type}
                                        <input type="radio" name="pur_type" title="{$v.val}" value="{$v.id}" checked lay-filter="pur_type">
                                        {else/}
                                        <input type="radio" name="pur_type" title="{$v.val}" value="{$v.id}" lay-filter="pur_type">
                                        {/if}
                                        {/volist}
                                    </td>
                                    <td colspan="4" style="text-align: center;">
                                        <input type="text" class="layui-input" autocomplete="off" name="remark" value="{$model.remark??''}" placeholder="备注">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            {/if}
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="save" verify="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

<div id="getcolor_url" style="display: none;">{:U('purchase.main/color')}</div>
<div id="fabricList_url" style="display: none;">{:U('purchase.main/fabric')}</div>
<div id="ismobile" style="display: none;">{:ismobile()}</div>
<script>
	layui.use(['form', 'jquery', 'uploads','common','mycomm','laydate'], function () {
		let form = layui.form;
		let $ = layui.jquery;
		let laydate = layui.laydate;
		let common = layui.common;
		let mycomm = layui.mycomm;
		
		laydate.render({
			elem: '#create_time' ,//指定元素
			value:'{$model.create_time??''}',
			type:'datetime'
		});
	
		mycomm.editSubmit('',function(){
			if(window.name==''){
				location.href="{:U('purchase.main/index')}";
			}
		});
        
        $(document).ready(function(){
          //$('#js-groupId').focus();
            get_fabric_list();
            
            $('.pc-box #aitext').on('keydown', function(e) {
                if (e.keyCode === 13 && !e.shiftKey) { // 按下回车且没按Shift
                  e.preventDefault(); // 阻止默认换行行为
                  ai_read(); // 调用AI识别函数
                }
            });
            
            //点击AI识别按钮
            $('.ai-read-but').on('click', function() {
                ai_read(); // 调用AI识别函数
            });
        });
		
        //AI识别请求
        function ai_read(){
            var content = $('#aitext').val().trim();
            
            if (content) {
              load_show('AI识别中...')
              
              // 发起POST请求（替换成你的API地址）
              $.post("{:U('purchase.main/ai_read_info')}", { text: content })
                .done(function(res) {
                  load_hide();
                  if(res.code==0){
                      fillFormData(res.data); // 调用函数
                  }else{
                     Alert(res.msg,'error',3); 
                  }
                  // 这里处理返回结果 res
                  console.log(res);
                })
                .fail(function(err) {
                    load_hide();
                    Alert('识别失败，请重试！','error',3);
              });
            }else{
                Alert('识别内容不能为空！','error',3);
            }
        }
        
		function resize_group_width(){
		//改变窗口同步宽度
			$(window).resize(function() {
			  resize_group_width();
			});
            $('#groupid').width($('#js-groupId').width()+24);
		}
		
		resize_group_width();
		
		//获取产品数据
		function get_fabric_list(){
			var url=$("#fabricList_url").html();
			var data={};
			$.post(url,data,function(res){
				fabricList=res;
			},'json');
		}
        
        //填充表单数据到指定行
        function fillFormData(data) {
            
            // 正确获取数据源：从data的每个元素中提取list并合并
            const allList = data.list;
            // 修复选择器：确保HTML中的使用class="list-table-row"
            const rows = $('.list-table-row');
            const totalRows = rows.length;
            
            // 无数据时提示
            if (allList.length === 0) {
                layer.msg('无有效数据', {icon: 2});
                return;
            }
            
            // 遍历填充数据
            allList.forEach((rowData, index) => {
                let row = rows.eq(index);

                // 动态添加行（数据行超出页面现有行时）
                if (index >= totalRows) {
                    const template = rows.eq(0).clone(true);
                    template.find('input, select').val('');
                    template.find('td:first').text(index + 1);
                    template.appendTo(rows.parent());
                    row = template;
                }
                
                // 仅填充接口实际返回的字段（避免undefined错误）
                const fields = {
                    'input[name="info[fabric_code][]"]': rowData.fabric_code || '',
                    'input[name="info[color_code][]"]': rowData.color_code || '',
                    'input[name="info[color_name][]"]': rowData.color_name || '',
                    'input[name="info[count][]"]': rowData.count || '',
                    'select[name="info[unit][]"]': rowData.unit || '米'
                };
                
                // 填充值
                Object.entries(fields).forEach(([selector, value]) => {
                    const element = row.find(selector);
                    element.val(value);
                    if (element.is('select')) {
                        element.trigger('change'); // 触发Layui更新
                    }
                });
                
                // 触发blur事件
                setTimeout(() => {
                    row.find('input[name="info[fabric_code][]"]').trigger('blur');
                    row.find('input[name="info[color_code][]"]').trigger('blur');
                }, 50);
            });
            
            // 超出行数提示
            if (allList.length > rows.length) {
                layer.msg(`填充了前${rows.length}行数据，其余未显示`, {icon: 1});
            }
            
            const purTypeValue = data.pur_type.toString(); // 确保类型匹配

            $(`input[name="pur_type"][value="${purTypeValue}"]`)
              .prop('checked', true)
              .next('.layui-form-radio').click(); // 触发 Layui 样式更新
                
            // 渲染 Layui 表单
            form.render('radio');
        }
		
	})
</script>
<script src="__TPL_JS__/purchase/add.js?v=1.0.0&t={:time()}"></script>
{if !$action_up}
<!-- <script src="__TPL_JS__/purchase/staff-search.js?&t={:time()}"></script> -->
{/if}
{$LOAD_STYLE.bottom|raw}
</body>
</html>